package service

import "github.com/go-programming-tour-book/blog-service/internal/model"

type GetAddressRequest struct {
	ID uint32 `form:"id" binding:"required"`
}

type AddressListRequest struct {
	UserId uint32 `form:"user_id" binding:"required"`
}

type CreateAddressRequest struct {
	model.Model
	UserId       uint32 `form:"user_id" binding:"required"`
	Province     string `form:"province" binding:"required"`
	City         string `form:"city" binding:"required"`
	District     string `form:"district" binding:"required"`
	Address      string `form:"address" binding:"required"`
	Zip          string `form:"zip" binding:"required"`
	ContactName  string `form:"contact_name" binding:"required"`
	ContactPhone string `form:"contact_phone" binding:"required"`
}

type UpdateAddressRequest struct {
	model.Model
	Province     string `form:"province" binding:"required"`
	City         string `form:"city" binding:"required"`
	District     string `form:"district" binding:"required"`
	Address      string `form:"address" binding:"required"`
	Zip          string `form:"zip" binding:"required"`
	ContactName  string `form:"contact_name" binding:"required"`
	ContactPhone string `form:"contact_phone" binding:"required"`
}

type DeleteAddressRequest struct {
	ID uint32 `form:"id" binding:"required"`
}

func (svc *Service) GetAddressList(param *AddressListRequest) ([]*model.UserAddress, error) {
	return svc.dao.GetAddressList(param.UserId)
}

func (svc *Service) CountAddress(param *AddressListRequest) (int, error) {
	return svc.dao.CountAddress(param.UserId)
}

func (svc *Service) GetAddress(param *GetAddressRequest) (model.UserAddress, error) {
	return svc.dao.GetAddress(param.ID)
}

func (svc *Service) CreateAddress(param *CreateAddressRequest) error {
	return svc.dao.CreateAddress(param.UserId, param.Province, param.City, param.District, param.Address, param.Zip, param.ContactName, param.ContactPhone)
}

func (svc *Service) UpdateAddress(param *UpdateAddressRequest) error {
	return svc.dao.UpdateAddress(param.Model.ID, param.Province, param.City, param.District, param.Address, param.Zip, param.ContactName, param.ContactPhone)
}

func (svc *Service) DeleteAddress(param *DeleteAddressRequest) error {
	return svc.dao.DeleteAddress(param.ID)
}
